smart pointers, be careful when using pointers as elements of containers, in this case, you need to manage the memory yourself.
For example:
Example 9: Use the smart pointer shared_ptr In the boost library to wrap the pointer:
# Include # Include # Include # Include # Include # Include # Include
Using namespace std;
Class CTest{Public:CTest (const string str, int iPrice): m_strName (str), m_iPrice (iPrice ){}Void vPrint (){Cout }
Private:String m_s
Since it is not possible to put all the code in a file in programming, it is certain that some of the code will be open, so it is not difficult to make a file call in those high-level languages such as c++,c#. So in Lua,
These can be achieved as well. The Require function is used primarily. Here is the code to tell you.
The file being called Berequired.lua
--Private Functions
local function myprivatefunction ()
print ("This is a private function!")
End
--common interface
function
also delete it. This can be done by calling the member function erase () of the container.
Example 6:
Void main (){Vector
Int I;
For (I = 0; I {VectInt. push_back (I );
If (3 = I){VectInt. push_back (I );}}
VectInt. erase (remove (vectInt. begin (), vectInt. end (), 3), vectInt. end ());
Cout
For (I = 0; I {Cout }}
The running result is:
After deleted, size = 4 // you can see from this line that the container size has changed after deletion.
I = 0, 0
I = 1, 1
I = 2, 2
I = 3, 4
The result show
without indentation is the highest level. This indentation is strictly controlled, and the interpreter determines which part of the current code is in terms of indentation, which means that the indentation replaces the curly brace.The next step is to describe how the function is written, first, before the function name, def indicates that it is followed by a function, and then a colon at the end of the parenthesis, and the indentation part is the function content.def printmyname (name): Print N
done by calling the member function erase () of the container.
Example 6:
Void main (){
Vector
Int I;
For (I = 0; I
VectInt. push_back (I );
If (3 = I ){
VectInt. push_back (I );
}
}
VectInt. erase (remove (vectInt. begin (), vectInt. end (), 3), vectInt. end ());
Cout
For (I = 0; I
Cout
}
}
The running result is:
After deleted, size = 4 // you can see from this line that the container size has changed after deletion.
I = 0, 0
I = 1, 1
I = 2, 2
I = 3, 4
The result shows that all elements w
3.3 DebuggerDebugging is an essential part of the application development process, so it is very important to have a good debugger, unfortunately, Go in this aspect of development is not very perfect. Currently available debuggers are GDB, the latest version is built in the integrated development environment Liteide and Goclipse, but the debugger is not flexible and difficult to operate.If you do not want to use the debugger, you can follow some of the following useful methods to achieve the pur
dictionary---also known as a key-value pairCreate a dictionaryeg>>> person={... "Name": ' Tanjie ',... "Age": 21,... "Gender": ' Man '... }Find the elements inside the dictionary:egperson["Name"]In-Dictionary loops:1.eg for inch Person : Print # the printed ele is just the key in the dictionaryThe use of 2.person.items ()----gets all the elementsegFor k,v in Person.items (): #将字典里面的键赋值给key, value assigned to Vprint kprint
command execution status;Case is used to determine whether to execute a statement in a branch based on the true or false results of matching values saved in the variable with the specified mode;2. if each branch does not need to end with a separate end tag, and each branch of case must end;
Write a script for managing user accounts. The fourth edition uses the case statement + for loop to simultaneously create and delete users;
#! /Bin/bash## Helps function, displaying prompt information and he
, the starting vertex v0 into the stack, its corresponding visited[v0]=1, the iterative process is as follows:(1) Check whether the stack s is empty, if NULL then the iteration ends.(2) POPs a vertex v from the stack and accesses v.(3) Press the visited[i]=0 adjacent vertex of V into the stack and place its visited value at 1.(4) Implementation steps (1)DFS (head,v0,visited.).DFS1. [Initialize]For i==0 to N-1 do visited[i]=0.Visited[v0]=1.sdfs.2[non-recursive depth-first traversal]While S is not
example, if we want to add a vector to each line of the matrix, we can do that.# Add V to each row of x and store the result in Y X= nd.array ([[1,2,3], [4,6], [7,8,9], [ 10, 11, 12]]) v = nd.array ([1, 0, 1]) y = nd.zeros_like (x) # Create an empty matrix with the same shape as Xfor I in range (4): Y[i,:] = x[i,:] + vprint (y) This is going to work, but when the x matrix is very large, it can be very slow to calculate by using loops. We can c
TCP SYN probing.-UUsing UDP datagram probing, this is the default probing method.-DEnable the Socket-level debug feature (if supported by the Linux kernel).-FSet the Don ' t Fragment bit and do not allow IP packet fragmentation.-F First_ttlSets the size of the live value TTL for the first instrumented packet, with a default value of 1.--helpPrinting Help information-M Max_ttlSpecifies the maximum number of hops at the time of the probe, which is the maximum TTL value, and the default value is 3
version information: Nslookup–class=chaos–q=txt Version.bindView hardware information: DMESG | MoreDisplay peripheral information, such as USB, NIC, etc.: LSPCITo view the loaded drivers:LsnodLshwTo view the current processor type and speed (frequency): Psrinfo-vPrint the current OBP version number: Prtconf-vView hard disk physical information (vendor, RPM, capacity): Iostat–eTo view the geometry parameters and partition information for a disk: prtvt
correct")# break# Else:# Print ("Input error")# s = input ("Do you want to re-enter? ")# if s = = "No":# break# Else:# continue########################### #摘抄至网络 #############################################29. Develop the sensitive Word filter program, prompt the user to enter content, if the user input content contains special characters: "Teacher Cang", "Tokyo Hot", then replace the content with * * *V=input (">>>")V1=v.replace ("Cang teacher", "* * *")V2=v1.replace ("Tokyo Hot", "* * *")Pri
input, the content entered by the user is displayed in a tabular format.#!/usr/bin/env python#-*-Encoding:utf8-*-s = "" While True: name = input ("User name:") if name = = "Q" or name = = "Q": break If Len (name) >=: name = name[:20] passwd = input ("Password:") If Len (passwd) >=: passwd = passwd[:20] email = input ("email:") if Len (email) >=: email = email[:20] template = "{0}\t{ 1}\t{2}\n " v = Template.format (name, passwd, email) s
The traversal of a dictionary:
First of all:
Items ():
Function: Returns the dictionary key value pair in the form of a list
eg
Dict_={"A": 2, "B": 3, "C": 6}
Dict_.items ()
>>>[(' A ', 2), (' B ', 3), (' C ', 6)]
Iteritems ():
Function: Returns a dictionary key value pair with an iterator object
#-*-coding:cp936-*-Dict1={' A ': 1, ' B ': 2, ' C ': 3}#第一种:For D in Dict1:Print "%s:%d"% (D,dict1[d])Print#第二种:For k,v in Dict1.items ():Print "%s:%d"% (k,v)Print#第三种:For k,v in Dict1.iteritems ():Pri
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.